package com.example.sicnuaccountingapp.utils

import android.transition.ChangeBounds
import android.transition.Fade
import android.transition.TransitionManager
import android.transition.TransitionSet
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.transition.MaterialContainerTransform
import com.google.android.material.transition.MaterialElevationScale
import com.google.android.material.transition.MaterialFadeThrough
import com.google.android.material.transition.MaterialSharedAxis

object TransitionUtils {
    fun setupTransitions(fragment: Fragment) {
        fragment.apply {
            enterTransition = MaterialFadeThrough()
            exitTransition = MaterialFadeThrough()
            reenterTransition = MaterialFadeThrough()
        }
    }

    fun setupSharedAxisTransition(fragment: Fragment, axis: Int = MaterialSharedAxis.X) {
        fragment.apply {
            enterTransition = MaterialSharedAxis(axis, true)
            returnTransition = MaterialSharedAxis(axis, false)
            exitTransition = MaterialSharedAxis(axis, true)
            reenterTransition = MaterialSharedAxis(axis, false)
        }
    }

    fun setupElevationScale(fragment: Fragment) {
        fragment.apply {
            exitTransition = MaterialElevationScale(false)
            reenterTransition = MaterialElevationScale(true)
        }
    }

    fun setupContainerTransform(fragment: Fragment) {
        fragment.apply {
            sharedElementEnterTransition = MaterialContainerTransform().apply {
                drawingViewId = android.R.id.content
                duration = 300L
                scrimColor = android.graphics.Color.TRANSPARENT
            }
        }
    }

    fun animateLayoutChanges(viewGroup: ViewGroup, duration: Long = 300) {
        TransitionManager.beginDelayedTransition(viewGroup, TransitionSet().apply {
            addTransition(ChangeBounds())
            addTransition(Fade())
            this.duration = duration
        })
    }
} 